﻿
<%@ Page Language="c#" Inherits="Mysoft.Crm.Web.Tools.Views.ShareDialog" CodeBehind="Mysoft.Crm.Application.Pages.Tools.dll" %>
<%@ Register TagPrefix="crm" Namespace="Mysoft.Crm.Controls" Assembly="Mysoft.Crm.Application.Components.UI" %>
<html>
<head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"/>
<title>Share View</title>
<link rel="stylesheet" type="text/css" href="/_common/styles/global.css">
<link rel="stylesheet" type="text/css" href="/_common/styles/dialogs.css">
<link rel="stylesheet" type="text/css" href="/_nav/taskbox.css">
<style>

	TD.gridspacer
	{
		width:				2px;
	}

	TD.gridheader
	{
		padding-left:		8px;
	}

	TABLE.gridheader
	{
		background-color:	#e9e7d7;
		background-image:	url(/_grid/imgs/bar_bk.gif);
		font-size:			11px;
		width:				100%;
		height:				22px;
		border:				1px solid #dbdac9;
		border-bottom:		1px solid #c5c1b1;
	}

	IMG.icon
	{
		margin-left:		2px;
		margin-right:		5px;
	}

	input
	{
		border:0px;
	}

</style>

<script language="javascript" src="/_common/scripts/global.js"></script>
<script language="javascript" src="/_controls/lookup/lookup.js"></script>
<script language="javascript" src="/Tools/ViewEditor/Scripts/objects.js"></script>

<script language="JavaScript">

	// Used to determine if the Team list hast changed
	//
	var _bDelta = false;

	function share()
	{
		var o = LookupObjects(null, "single", "BasicOwner", 9, 0);

		if (o && o.items.length > 0)
		{
			for (var i = 0; i < o.items.length; i++)
			{
				if (!teamExists(o.items[i].id))
				{
					var oNewTr = tblTeams.insertRow();

					oNewTr.sGuid = o.items[i].id;

					var oNewTd = oNewTr.insertCell(0);

					oNewTd.innerHTML = "<input type=checkbox>";

					oNewTd = oNewTr.insertCell(1);
					oNewTd.innerHTML = o.items[i].html;
				}
			}

			tblTeamGrid.disabled = false;

			updateDelta();
		}
	}


	function teamExists(sGuid)
	{
		for (var i=0; i < tblTeams.rows.length; i++)
		{
			if (tblTeams.rows[i].sGuid == sGuid)
			{
				return true;
			}
		}

		return false;
	}

	function Ok(bMakePublic)
	{
		var s = "";

		if (!bMakePublic)
		{
			for (var i = 0; i < tblTeams.rows.length; i++)
			{
				s += tblTeams.rows[i].sGuid;

				if (i != tblTeams.rows.length - 1)
				{
					s += ",";
				}
			}
		}
		else
		{
			if(!confirm( "Making this view public will remove all current share settings.  Would you like to continue?" ))
			{
				return false;
			}
		}

		if (s == "" && !bMakePublic)
		{
			if(confirm( "You have selected not to share this view with any teams. This will cause  this view to become public. Would you like to continue?" ))
			{
				bMakePublic = true;
			}
			else
			{
				return false;
			}
		}

		if (_bDelta || bMakePublic)
		{
			var iParam = (bMakePublic ? "1" : "0");
			var oXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
				oXmlHttp.Open("POST", "/tools/vieweditor/cmds/cmd_ShareView.aspx?id=<%=queryId%>&makePublic=" + iParam, false);
				oXmlHttp.Send(s);
		}

		window.close();
	}


	function SelectAll()
	{
		for (var i=0; i < tblTeams.rows.length; i++)
		{
			tblTeams.rows[i].cells[0].firstChild.checked = event.srcElement.checked;
		}
	}


	function RemoveTeams()
	{
		for (var i=0; i < tblTeams.rows.length; i++)
		{
			if (tblTeams.rows[i].cells[0].firstChild.checked)
			{
				tblTeams.deleteRow(i);
				i--;

				updateDelta();
			}
		}
	}


	function updateDelta()
	{
		_bDelta = true;
		btnDialogOk.disabled = false;
	}

</script>
</head>

<body>

<table style="width:100%; height:100%;" cellspacing="0" cellpadding="8">
	<tr>
		<td class="header">
			<div class="header">Share This View</div>
			<div class="headerdesc">Decide how you want this view to be shared with other users.</div>
		</td>
	</tr>
	<tr>
		<td class="main">

			<table width="100%" height="100%">
				<col width="160"><col>
				<tr>
					<td><crm:TaskBox runat="server" id="crmTaskBox"/></td>
					<td valign="top">
						<table width="100%" height="100%" cellspacing="0" cellpadding="0">
<%

	// See if we have any teams
	//
	if (publicView)
	{

%>
						<tr>
							<td>
								<table width="100%" cellpadding="2" cellspacing="2">
									<tr>
										<td valign="top"><img src="/_imgs/ico/16_info.gif"></td>
										<td>
											This view is currently public, which means it is available to all users. To restrict access to this view, you must add one or more teams. To do this, in Common Tasks, click Add Team.
										</td>
									</tr>
								</table>
								<br>
							</td>
						</tr>
<%
	}
%>
						<tr height="100%">
							<td>
								<table id="tblTeamGrid" width="100%" height="100%" cellspacing="0" cellpadding="0" <%=(publicView ? "disabled" : "")%>>
									<tr height="22">
										<td>
											<table cellpadding="0" cellspacing="0" class="gridheader">
												<tr>
													<td width="24" style="padding-left: 4px;"><input type="checkbox" class="checkbox" onclick="SelectAll();"></td>
													<td class="gridspacer"><img src="/_grid/imgs/bar_line.gif"></td>
													<td class="gridheader">Team Name</td>
													<td width="14">&nbsp;</td>
												</tr>
											</table>
										</td>
									</tr>
									<tr>
										<td>
											<div style="background-color: #ffffff; height: 100%; border-right: 1px solid #cccccc;border-left: 1px solid #cccccc; border-bottom: 1px solid #cccccc; overflow-y: scroll; overflow-x: hidden;">

												<table id="tblTeams" width="100%" cellspacing="0" cellpadding="3" style="table-layout:fixed;">
												<col width="24"><col style="padding-left:10px;">
<%
												if (!publicView)
												{
													Response.Write(teamList.ToString());
												}
%>
												</table>

											</div>
										</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
				</td>
				</tr>
			</table>

		</td>
	</tr>
	<tr>
		<td class="buttons">
			<button id="btnDialogOk" onclick="Ok();" disabled>OK</button>
			&nbsp;
			<button onclick="window.close()">Cancel</button>
		</td>
	</tr>
</table>

</body>
</html>